package view;

import java.awt.BorderLayout;
import java.awt.SystemColor;

import javax.swing.ComboBoxModel;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.RowSorter;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableCellEditor;

import model.BuyTableModel;
import model.Database;
import model.DatePicker;
import model.Employee;
import model.NumberCellEditor;
import model.NumberRenderer;
import model.OptionMessenger;
import model.Partner;
import model.StoreImages;
import model.FormatFactory;
import model.UICommand;

import org.jdesktop.swingx.JXTable;

import com.alee.laf.WebLookAndFeel;
import com.alee.laf.button.WebButton;
import com.alee.laf.toolbar.WebToolBar;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import controller.BuyController;

import java.awt.Color;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;

public class BuyPanel extends JPanel {
	private static final long serialVersionUID = -2688533316758084774L;
	private JXTable table;
	private JTextField txtSumMoney;
	private JTextField txtSumTax;
	private JTextField txtPayment;
	private JTextField txtBill;
	private JPanel produc;
	private JComboBox<Object> comboBoxType;
	private JComboBox<Object> comboBoxProvider;
	private JComboBox<Object> comboBoxName;
	private JComboBox<Object> comboBoxID;
	private Connection connect;
	private JComboBox<Employee> cbxEmpl;
	private ArrayList<Partner> listPartner;
	private JComboBox<Object> cbxPartner;
	private JTextField txtAddress;
	private JTextField txtPhone;
	private JTextField txtFax;
	private JTextField txtEmail;
	private JTextArea textArea;
	private JComboBox<Object> comboBoxUnit;
	private JXDatePicker datePicker;
	private JComboBox<String> cbxPmtOption;

	public BuyPanel(BuyTableModel tableModel, BuyController control,
			boolean tollBar) {
		this.listPartner = new ArrayList<Partner>();
		setLayout(new BorderLayout(0, 0));

		JSplitPane splitPane = new JSplitPane();
		this.add(splitPane, BorderLayout.CENTER);
		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setOneTouchExpandable(true);
		splitPane.setResizeWeight(0.1);

		JPanel infor = new JPanel();
		splitPane.setLeftComponent(infor);
		infor.setLayout(new BorderLayout(0, 0));

		JPanel detailBill = new JPanel();
		infor.add(detailBill, BorderLayout.NORTH);
		detailBill.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"),
				"Chi ti\u1EBFt h\u00F3a \u0111\u01A1n", TitledBorder.LEADING,
				TitledBorder.TOP, null, SystemColor.textHighlight));
		detailBill.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.BUTTON_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.PREF_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.BUTTON_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("right:default:grow"), },
				new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

		JLabel lblBill = new JLabel("Mã HĐ");
		detailBill.add(lblBill, "1, 1, left, default");

		txtBill = new JTextField(getIDBill());
		txtBill.setBackground(Color.WHITE);
		txtBill.setEditable(false);
		detailBill.add(txtBill, "3, 1, fill, default");
		txtBill.setColumns(18);

		JLabel lblEmpl = new JLabel("Nhân viên lập");
		detailBill.add(lblEmpl, "5, 1, left, default");

		// TODO employee
		cbxEmpl = new JComboBox<Employee>();
		cbxEmpl.setModel(loadDataEmpl());
		cbxEmpl.setSelectedIndex(-1);
		cbxEmpl.setPreferredSize(txtBill.getPreferredSize());
		AutoCompleteDecorator.decorate(cbxEmpl);
		detailBill.add(cbxEmpl, "7, 1, fill, default");

		JLabel lblDate = new JLabel("Ngày lập");
		detailBill.add(lblDate, "9, 1, left, default");

		datePicker = DatePicker.createDatePicker(
				DatePicker.DEFAULT_WIDTH_COLUMN, DatePicker.DEFAULT_ICON);
		detailBill.add(datePicker, "11, 1");

		JPanel information = new JPanel();
		infor.add(information, BorderLayout.CENTER);
		information.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"),
				"Th\u00F4ng tin nh\u00E0 ph\u00E2n ph\u1ED1i",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.textHighlight));
		information.setLayout(new BorderLayout(0, 7));

		JPanel detail = new JPanel();
		information.add(detail, BorderLayout.NORTH);
		detail.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"), }, new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, }));

		JLabel lblName = new JLabel("Tên NPP");
		detail.add(lblName, "1, 1, left, default");

		// TODO combobox partner
		cbxPartner = new JComboBox<Object>();
		loadDataPartner();
		cbxPartner.setSelectedIndex(-1);
		cbxPartner.setEditable(true);
		cbxPartner.setActionCommand("partner");
		cbxPartner.addActionListener(control);
		AutoCompleteDecorator.decorate(cbxPartner);
		detail.add(cbxPartner, "3, 1, 5, 1, fill, default");

		JLabel lblAddress = new JLabel("Địa chỉ");
		detail.add(lblAddress, "1, 3, left, default");

		txtAddress = new JTextField();
		detail.add(txtAddress, "3, 3, 5, 1, fill, top");
		txtAddress.setColumns(10);

		JLabel lblPhone = new JLabel("Điện thoại");
		lblBill.setPreferredSize(lblPhone.getPreferredSize());
		detail.add(lblPhone, "1, 5, left, default");

		WebButton btnNewBill = new WebButton("");
		btnNewBill.setRolloverDecoratedOnly(true);
		btnNewBill.setToolTipText("Tạo mới hóa đơn");
		btnNewBill.setActionCommand("new");
		btnNewBill.addActionListener(control);
		btnNewBill.setFocusable(false);
		btnNewBill.setIcon(new ImageIcon(BuyPanel.class
				.getResource("/images/new_bill.png")));
		detailBill.add(btnNewBill, "13, 1");

		txtPhone = new JTextField();
		detail.add(txtPhone, "3, 5, fill, default");
		txtPhone.setColumns(10);

		JLabel lblFax = new JLabel("Fax");
		detail.add(lblFax, "5, 5, right, default");

		txtFax = new JTextField();
		detail.add(txtFax, "7, 5, fill, default");
		txtFax.setColumns(10);

		JLabel lblEmail = new JLabel("Email");
		detail.add(lblEmail, "1, 7, left, default");

		txtEmail = new JTextField();
		detail.add(txtEmail, "3, 7, 5, 1, fill, default");
		txtEmail.setColumns(10);

		JScrollPane note = new JScrollPane();
		information.add(note);
		note.setViewportBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "Ghi ch\u00FA",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.activeCaption));

		textArea = new JTextArea();
		textArea.setRows(2);
		note.setViewportView(textArea);

		produc = new JPanel();
		splitPane.setRightComponent(produc);
		produc.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "S\u1EA3n ph\u1EA9m",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.textHighlight));
		produc.setLayout(new BorderLayout(0, 7));

		JScrollPane list = new JScrollPane();
		list.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		list.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		produc.add(list, BorderLayout.CENTER);

		// TODO table
		table = new JXTable(tableModel);
		table.setSurrendersFocusOnKeystroke(true);
		table.setHorizontalScrollEnabled(true);
		table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		table.getTableHeader().setReorderingAllowed(false);
		table.setFillsViewportHeight(true);
		list.setViewportView(table);

		// temp
		table.getColumnModel().getColumn(0)
				.setCellRenderer(new NumberRenderer());
		table.getTableHeader().setToolTipText("Test Tool Tip");

		final JPopupMenu popupMenu = new JPopupMenu();

		JMenuItem mntmngXut = new JMenuItem("Pack All");
		mntmngXut.setIcon(StoreImages.getIcon(StoreImages.LOGOUT_ICON));
		popupMenu.add(mntmngXut);

		JMenuItem mntmThot = new JMenuItem("Thoát");
		mntmThot.setIcon(StoreImages.getIcon(StoreImages.EXIT_ICON));
		popupMenu.add(mntmThot);

		// TODO cell editor
		for (int i = 8; i < tableModel.getColumnCount(); i++) {
			table.getColumnModel()
					.getColumn(i)
					.setCellEditor(new NumberCellEditor(new Double(0), control));
		}
		table.getColumnModel().getColumn(6)
				.setCellEditor(new NumberCellEditor(new Integer(0), null));
		table.getColumnModel().getColumn(7)
				.setCellEditor(new NumberCellEditor(new Integer(0), control));

		// TODO combobox cell editor
		this.comboBoxType = new JComboBox<Object>();
		this.comboBoxType.setEditable(true);

		this.comboBoxProvider = new JComboBox<Object>();
		this.comboBoxProvider.setEditable(true);

		this.comboBoxID = new JComboBox<Object>();
		this.comboBoxID.setEditable(true);

		this.comboBoxName = new JComboBox<Object>();
		this.comboBoxName.setEditable(true);

		this.comboBoxUnit = new JComboBox<Object>();
		this.comboBoxUnit.setEditable(true);

		AutoCompleteDecorator.decorate(this.comboBoxType);
		AutoCompleteDecorator.decorate(this.comboBoxProvider);
		AutoCompleteDecorator.decorate(this.comboBoxID);
		AutoCompleteDecorator.decorate(this.comboBoxName);
		AutoCompleteDecorator.decorate(this.comboBoxUnit);

		tableModel.createComboBox(comboBoxID, 1);
		tableModel.createComboBox(comboBoxType, 2);
		tableModel.createComboBox(comboBoxName, 3);
		tableModel.createComboBox(comboBoxProvider, 4);
		tableModel.createComboBox(comboBoxUnit, 5);

		table.getColumnModel().getColumn(1)
				.setCellEditor(new ComboBoxCellEditor(comboBoxID));
		table.getColumnModel().getColumn(3)
				.setCellEditor(new ComboBoxCellEditor(comboBoxName));
		table.getColumnModel().getColumn(2)
				.setCellEditor(new ComboBoxCellEditor(comboBoxType));
		table.getColumnModel().getColumn(4)
				.setCellEditor(new ComboBoxCellEditor(comboBoxProvider));
		table.getColumnModel().getColumn(5)
				.setCellEditor(new ComboBoxCellEditor(comboBoxUnit));

		// alignment center
		FormatFactory.formatHeader(table, SwingConstants.CENTER);
		FormatFactory.formatHighlighter(table, null);

		// TODO function
		JPanel paymentPanel = new JPanel();
		this.add(paymentPanel, BorderLayout.SOUTH);
		paymentPanel.setBorder(new TitledBorder(UIManager
				.getBorder("TitledBorder.border"), "Thanh to\u00E1n",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.textHighlight));
		paymentPanel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"), }, new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, }));

		JLabel lblSumMoney = new JLabel("Tổng thành tiền");
		paymentPanel.add(lblSumMoney, "1, 1, left, default");

		txtSumMoney = new JTextField();
		txtSumMoney.setBackground(Color.WHITE);
		txtSumMoney.setEditable(false);
		paymentPanel.add(txtSumMoney, "3, 1, fill, default");
		txtSumMoney.setColumns(10);

		JLabel lblTngThu = new JLabel("Tổng tiền thuế");
		paymentPanel.add(lblTngThu, "5, 1, left, default");

		txtSumTax = new JTextField();
		txtSumTax.setBackground(Color.WHITE);
		txtSumTax.setEditable(false);
		paymentPanel.add(txtSumTax, "7, 1, fill, default");
		txtSumTax.setColumns(10);

		JLabel lblPayment = new JLabel("Tiền thanh toán");
		paymentPanel.add(lblPayment, "1, 3, left, default");

		txtPayment = new JTextField();
		txtPayment.setBackground(Color.WHITE);
		txtPayment.setEditable(false);
		paymentPanel.add(txtPayment, "3, 3, fill, default");
		txtPayment.setColumns(10);

		JLabel lblPmtOption = new JLabel("Hình thức thanh toán");
		paymentPanel.add(lblPmtOption, "5, 3, left, default");

		cbxPmtOption = new JComboBox<String>();
		ComboBoxModel<String> aModel = new DefaultComboBoxModel<>(new String[] {
				"Tiền mặt", "Chuyển khoản" });
		cbxPmtOption.setModel(aModel);
		cbxPmtOption.setEditable(true);
		AutoCompleteDecorator.decorate(cbxPmtOption);
		cbxPmtOption.setBackground(Color.WHITE);
		paymentPanel.add(cbxPmtOption, "7, 3, fill, default");

		if (tollBar)
			addToolBar(control);
	}

	public int[] getSelectedRows() {
		int[] selectedRow = table.getSelectedRows();
		int[] realRow = new int[table.getSelectedRowCount()];
		for (int i = 0; i < realRow.length; i++) {
			realRow[i] = table.convertRowIndexToModel(selectedRow[i]);
		}
		return realRow;
	}

	public void setValue(String sumMoney, String sumTax, String payment) {
		this.txtSumMoney.setText(sumMoney);
		this.txtSumTax.setText(sumTax);
		this.txtPayment.setText(payment);
	}

	public void addToolBar(BuyController control) {
		// TODO tool bar
		WebToolBar toolBar = new WebToolBar();
		FormatFactory.formatToolBar(toolBar);
		produc.add(toolBar, BorderLayout.EAST);

		toolBar.add(FormatFactory.createButtonToolBar("Thêm",
				UICommand.ADD_CMD, StoreImages.getIcon(StoreImages.NEW_ICON),
				control));
		toolBar.add(FormatFactory.createButtonToolBar("Refresh",
				UICommand.REFRESH_CMD,
				StoreImages.getIcon(StoreImages.REFRESH_ICON), control));
		toolBar.add(FormatFactory.createButtonToolBar("Xóa",
				UICommand.DELETE_CMD,
				StoreImages.getIcon(StoreImages.DELETE_ICON), control));
		toolBar.add(FormatFactory.createButtonToolBar("Tính tiền",
				UICommand.COMPUTING_CMD,
				StoreImages.getIcon(StoreImages.DOLLAR_ICON), control));
		toolBar.add(FormatFactory.createButtonToolBar("Lưu",
				UICommand.SAVE_CMD, StoreImages.getIcon(StoreImages.SAVE_ICON),
				control));
	}

	// TODO load data partner
	public void loadDataPartner() {
		try {
			if (connect == null)
				connect = Database.connect();

			PreparedStatement pre = connect
					.prepareStatement("SELECT * FROM partner WHERE customer = 0");
			ResultSet rs = pre.executeQuery();

			while (rs.next()) {
				Partner p = new Partner();
				p.setId(rs.getInt("id"));
				p.setName(rs.getString("name"));
				p.setAddress(rs.getString("address"));
				p.setPhone(rs.getString("phone"));
				p.setFax(rs.getString("fax"));
				p.setEmail(rs.getString("email"));
				p.setNote(rs.getString("note"));

				this.listPartner.add(p);
				this.cbxPartner.addItem(p.getName() + " - ID:" + p.getId());
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void clearSortedRow() {
		RowSorter<?> rs = table.getRowSorter();
		rs.setSortKeys(null);
	}

	public void editCellAt(int row, int column) {
		table.editCellAt(row, column);
		System.out.println(table.getEditingRow());
	}

	public void stopCellEditing() {
		TableCellEditor cellEditor = table.getCellEditor();
		if (cellEditor != null)
			cellEditor.stopCellEditing();
	}

	// TODO create combobox employee
	private ComboBoxModel<Employee> loadDataEmpl() {
		try {
			Connection connect = null;

			if (connect == null)
				connect = Database.connect();

			PreparedStatement pre = connect
					.prepareStatement("SELECT * FROM employee INNER JOIN regency ON employee.regency = regency.name "
							+ "WHERE regency.id = 'BHG' ORDER BY employee.last_name ASC");
			ResultSet rs = pre.executeQuery();

			DefaultComboBoxModel<Employee> model = new DefaultComboBoxModel<>();
			while (rs.next()) {
				Employee e = new Employee();
				e.setId(rs.getInt("id_empl"));
				e.setFirstName(rs.getString("first_name"));
				e.setLastName(rs.getString("last_name"));
				e.setBirthday(rs.getDate("birthday"));
				e.setSex(rs.getString("sex"));
				e.setIdent(rs.getString("identification"));
				e.setAddress(rs.getString("address"));
				e.setPhone(rs.getString("phone"));
				e.setDateBegin(rs.getDate("date_begin"));
				e.setRegency(rs.getString("regency"));

				model.addElement(e);
			}
			return model;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	// TODO get id bill
	public String getIDBill() {
		try {
			if (connect == null)
				connect = Database.connect();

			PreparedStatement pre = connect
					.prepareStatement("SELECT max(id) + 1 FROM bill");
			ResultSet rs = pre.executeQuery();

			if (rs.first())
				return rs.getString(1);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "00";
	}

	// TODO show information partner
	public void setSelectedPartner() {
		if (cbxPartner.getSelectedIndex() != -1) {
			Partner p = this.listPartner.get(cbxPartner.getSelectedIndex());
			txtAddress.setText(p.getAddress());
			txtPhone.setText(p.getPhone());
			txtFax.setText(p.getFax());
			txtEmail.setText(p.getEmail());
			textArea.setText(p.getNote());
		} else {
			String text = "";
			txtAddress.setText(text);
			txtPhone.setText(text);
			txtFax.setText(text);
			txtEmail.setText(text);
			textArea.setText(text);
		}
	}

	public void deleteAll() {
		// set information this bill
		this.txtBill.setText(getIDBill());
		this.cbxEmpl.setSelectedIndex(-1);
		this.datePicker.setDate(new Date());

		// set combobox partner
		this.cbxPartner.setSelectedIndex(-1);

		// set text payment
		setValue("", "", "");
	}

	// TODO checkBill
	public boolean checkBill() {
		boolean result = true;
		if (this.cbxEmpl.getSelectedIndex() == -1) {
			result = false;
			OptionMessenger.showMessageDialog(
					OptionMessenger.windowForComponent(this),
					"Chưa chọn nhân viên lập hóa đơn", "Lỗi",
					OptionMessenger.ERROR_MESSAGE);
		} else {
			JFormattedTextField textField = datePicker.getEditor();
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			try {
				dateFormat.parse(textField.getText());
			} catch (ParseException e) {
				result = false;
				OptionMessenger.showMessageDialog(
						OptionMessenger.windowForComponent(this),
						"Ngày chọn không phù hợp", "Lỗi",
						OptionMessenger.ERROR_MESSAGE);
			}
		}
		return result;
	}

	// TODO check information partner
	public boolean checkPartner() {
		if (cbxPartner.getSelectedIndex() != -1) {
			if (!cbxPartner.getSelectedItem().equals("")
					&& !txtAddress.getText().equals("")) {
				return true;
			} else {
				OptionMessenger.showMessageDialog(
						OptionMessenger.windowForComponent(this),
						"Tên nhà phân phối và địa chỉ không được rỗng", "Lỗi",
						OptionMessenger.ERROR_MESSAGE);
			}
		} else {
			String text = (String) cbxPartner.getSelectedItem();
			if (text != null) {
				OptionMessenger.showMessageDialog(
						OptionMessenger.windowForComponent(this),
						"Vui lòng nhập đầy đủ thông tin nhà phân phối", "Lỗi",
						OptionMessenger.ERROR_MESSAGE);
			} else
				OptionMessenger.showMessageDialog(
						OptionMessenger.windowForComponent(this),
						"Chưa chọn thông tin nhà phân phối", "Lỗi",
						OptionMessenger.ERROR_MESSAGE);
		}
		return false;
	}

	public Partner getPartner() {
		if (cbxPartner.getSelectedIndex() != -1) {
			return this.listPartner.get(cbxPartner.getSelectedIndex());
		} else {
			Partner p = new Partner();
			p.setName((String) cbxPartner.getSelectedItem());
			p.setAddress(txtAddress.getText());
			p.setEmail(txtEmail.getText());
			p.setPhone(txtPhone.getText());
			p.setFax(txtFax.getText());
			p.setNote(textArea.getText());
			return p;
		}
	}

	public Employee getEmployee() {
		return (Employee) this.cbxEmpl.getSelectedItem();
	}

	public Date getDate() {
		return datePicker.getDate();
	}

	public String getPayment() {
		return (String) cbxPmtOption.getSelectedItem();
	}

	public static void main(String[] args) {
		WebLookAndFeel.install();
		JFrame frame = new JFrame();
		BuyTableModel tableModel = new BuyTableModel();
		BuyController control = new BuyController(tableModel);
		frame.getContentPane().add(control.getView());
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}

}
